<!--仓库搜索-->
<template>
    <div class="project-search-wrapper" ref="projectBoxRef">
        <a-table :scroll="{x:0,y:200}" :columns="columns" :data-source="tableData" :customRow="customClick" bordered :pagination="pagination" :loading="isSearch">
        </a-table>
    </div>
</template>
<script>
import { getAction, postAction } from "@/api/manage";

const columns = [
    { title: "仓库编码", width: 70, dataIndex: "whCode", },
    { title: "仓库名称", dataIndex: "whName", width: 120 },
];
export default {
    props: {

    },
    data() {
        return {
            pagination: {
                current: 1,
                pageSize: 20,
                total: 0,
                size: 'small',
                onChange: (page, pageSize) => {
                    this.pagination.current = page;
                    this.pagination.pageSize = pageSize;
                    this.getData();
                }
            },
            columns,
            tableData: [],
            customClick: (record, index) => ({
                on: {
                    click: (event) => {
                        event.preventDefault();
                        console.log('点击的行数', record, index);
                        this.$emit('check', record)
                    },
                },
            }),
            isSearch: false,
        }
    },
    created() {
        this.getData();
    },
    methods: {
        getData(val) {
            //获取右侧表数据
            let params = {
                current: this.pagination.current,
                size: this.pagination.pageSize,
                whCode: val,
            };
            if (!this.isSearch) {
                this.isSearch = true;

                // if (this.$route.path == '/inventory/bills/purchaseIn') { //表示是库存管理里的采购入库
                //     getAction("/in/warehouse/listMyOperationInWarehouses", params).then((response) => {
                //         if (response.code == 200) {
                //             console.log(response);
                //             if (val) {
                //                 this.tableData = response.data.filter(item => item.whCode == val || item.whName.indexOf(val) != -1)
                //             } else {
                //                 this.tableData = response.data;
                //             }
                //         } else {
                //             // this.$message.warning(response.message);
                //         }
                //         this.isSearch = false;
                //     });
                // } else {
                let apiUrl = '';
                let path = this.$route.path;
                if (path == '/inventory/bills/purchaseIn' || path == '/inventory/bills/productIn' || path == '/inventory/bills/saleOut' || path == '/inventory/bills/materialOut') {
                    //表示是库存管理里的采购入库 产成品入库 销售出库 材料出库
                    apiUrl = '/in/warehouse/listMyOperationInWarehouses';
                } else {
                    apiUrl = '/in/warehouse/pageList';
                }
                getAction(apiUrl, params).then((response) => {
                    if (response.code == 200) {
                        const { records, total, current, size } = response.data;
                        this.pagination.total = response.data.total;
                        let page = {
                            total: total,
                            pageSize: size,
                            current: current
                        }
                        this.pagination = Object.assign(this.pagination, page);
                        this.tableData = records;
                    } else {
                        // this.$message.warning(response.message);
                    }
                    this.isSearch = false;
                });
                // }

            }

        },
        handleEnter() {
            if (this.tableData != '' && this.tableData != null) {
                this.$emit('check', this.tableData[0])
            } else {
                this.$message.error('请选择一条数据')
                return;
            }
        },
        changePosition(position) {
            console.log(position);
            this.$nextTick(() => {
                this.$refs.projectBoxRef.style.left = (position.left - 200) + 'px';
            })
        }
    }
}
</script>
<style lang="less">
.project-search-wrapper {
    max-height: 350px;
    position: fixed;
    z-index: 100;
    border: 1px solid #a7abb0;
    width: 500px;
    // .ant-table-wrapper .ant-table-placeholder {
    //     position: static !important;
    //     top: 0;
    // }
    .ant-table-wrapper {
        background: #eee;
    }
    .ant-table-tbody {
        cursor: pointer;
    }
}
</style>